package com.shelpe.services.scheduler.item.customer;

import java.util.Calendar;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shelpe.services.scheduler.dto.RptCustomerDto;
import com.shelpe.services.scheduler.mongorepository.UnrecoverableErrorRepository;
import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.po.Users;
import com.shelpe.services.scheduler.syncclient.CustomerClient;
import com.shelpe.services.scheduler.util.Util;

@Component("customerProcessor")
public class CustomerProcessor implements ItemProcessor<Users, SyncLog>{

	@Autowired
	private CustomerClient cusClient;
	
	@Autowired
	private UnrecoverableErrorRepository errorRep;
	
	@Override
	public SyncLog process(Users item) throws Exception {
		// TODO Auto-generated method stub
		
		long userId = item.getUserId();
		if(errorRep.countByUserId(userId) > 0){
			return null;
		}
		
		Calendar cal = Calendar.getInstance();	  
		int hour=cal.get(Calendar.HOUR_OF_DAY);//小时	
		String record = hour > 8 ? "no" : "yes";
		RptCustomerDto rptDto = cusClient.syncRptCustomerByUserId(userId, record);
		
		return Util.convert(rptDto);
	}

}
